/**
 * Created by mac on 15-11-2.
 */
//点击 购买渠道 右侧投票
(function( $ ) {

    var olistUl = $('.list-content');

    olistUl.on('click', 'ul.vote li', function() {

        if ( !userServers.getUserInfo().userName ) {
            window.globalLayer.openLogin(); //打开登陆提示弹窗
            return;
        }

        var thisLi = $(this), thisHight = thisLi.find('.con');

        if ( thisHight.hasClass('current') ) return;

        var thisUl = thisLi.parent(),
            thisUgc = thisLi.parents('li.clearfix').eq(0);

        commentServers.ugcVote({
            'ugcId': thisUgc.attr('_ugcid'),
            'ugcType': thisUgc.attr('_ugctype'),
            'chooseChannel': thisLi.index()+1
        }, function( msg ) {
            if ( msg.error || msg.code != 200 ) {
                window.globalLayer.openWarning({'autoClose':true, time: 2000, text:msg.description});
                return;
            }

            //得到新数据，渲染投票区域
            thisUl.find('li').each(function(index, elem) {
                var oP = $(elem).find('p.num');

                $(elem).find('.con').removeClass('current');
                switch ( index ) {
                    case 0:
                        oP.text(msg.detail.goodChannelNum+'票');
                        break;
                    case 1:
                        oP.text(msg.detail.normalChannelNum+'票');
                        break;
                    case 2:
                        oP.text(msg.detail.badChannelNum+'票');
                        break;
                }
            });
            thisHight.addClass('current');
        });
    });

})( jQuery );